package com.wyl.log;

/**
 * 输出到控制台，带有堆栈信息，能够在控制台点击直接跳转
 * @author 吴宇亮 on 2023/6/8 9:53
 */
public class consoleWithLink {

    public static void main(String[] args) {
        method1();
    }

    public static void method1() {
        method2();
    }

    public static void method2() {
//        Throwable t = new Throwable();
//        StackTraceElement[] elements = t.getStackTrace();
//        StackTraceElement[] elements = Thread.currentThread().getStackTrace();
//        System.out.println(elements[1]);

        String log = "log: 这是一条日志信息 ";
        printLog(log);

        // 原理，只要输出这种格式，idea就能解析成跳转
//        System.out.println("com.wyl.log.consoleWithLink.method2(consoleWithLink.java:22)");
    }

    public static void printLog(String log) {
        System.out.println(new Throwable().getStackTrace()[1] + "\n" + log);
    }
}
